<template>
  <div class="cart-container" id="cart" ref="scollElement">
    <div class="cart-header">
      <div class="cartback" @click="cartback"></div>
      <div class="cart-header-title">购物车</div>
      <div class="more" @click="blackbtnclick">
         <div class="blackmenu" :class="{blackbtnactive:isblackclick==false}">
          <div class="blacktriankle"></div>
          <div class="blackmenubtn" @click="gotootherpage(0)">
            <div class="blackbtnlogo0"></div>
            <div class="blackbtndes">首页</div>
          </div>
          <div class="blackmenubtn" @click="gotootherpage(1)">
            <div class="blackbtnlogo1"></div>
            <div class="blackbtndes">分类搜索</div>
          </div>
          <div class="blackmenubtn" @click="gotootherpage(2)">
            <div class="blackbtnlogo2"></div>
            <div class="blackbtndes">购物车</div>
          </div>
          <div class="blackmenubtn" @click="gotootherpage(3)">
            <div class="blackbtnlogo3"></div>
            <div class="blackbtndes">我的京东</div>
          </div>
          <div class="blackmenubtn" @click="gotootherpage(4)">
            <div class="blackbtnlogo4"></div>
            <div class="blackbtndes">浏览记录</div>
          </div>
        </div>
      </div>
    </div>
    <div class="cart-body">
      <div v-if="!isAdd">
        <div class="cart-login" v-if="hasnotlogin">
          <img src="images/cart-big.png" alt />
          <p>登录后可同步购物车中商品</p>
          <div @click="login">登录</div>
        </div>
        <div class="jd-seckill">
          <span class="jd-seckill-text">京东秒杀</span>
        </div>
        <div class="jd-seckill-list">
          <div class="seckill">
            <div class="seckill-top">
              <div class="seckill-top-left">京东秒杀</div>
              <div class="seckill-top-right">
                <time-count></time-count>
              </div>
            </div>
            <div class="seckill-bottom">
              <div v-for="(item,index) in proList" :key="index" class="seckill-bottom-item">
                <img :src="item.url" class="seckill-bottom-img" />
                <p class="seckill-bottom-p">
                  ￥{{item.newprice}}
                  <del class="seckill-bottom-del">￥{{item.oldprice}}</del>
                </p>
              </div>

              <div class="get-more">
                <span>查看更多</span>
              </div>
            </div>
          </div>
        </div>
      </div>
      <cartadd-list v-if="isAdd"></cartadd-list>
      <div class="something-want-to">
        <span class="something-want-to-text">可能你还想要</span>
      </div>
      <div class="something-want-to-list" ref="want">
        <div class="each" v-for="(item,index) in cartPro" :key="index">
          <div class="each-top">
            <img v-lazy="item.imgsrc" alt />
          </div>
          <div class="each-bottom">
            <div class="each-des">
              <img src="images/ziying.png" alt />
              {{item.title}}
            </div>
            <div class="each-pri">
              <div class="each-pri-left">
                <div class="each-pri-left-one">￥{{item.newprice}}</div>
                <div class="each-pri-left-two" v-if="item.type">{{item.type}}</div>
                <del class="each-pri-left-three" v-if="item.oldprice">￥{{item.oldprice}}</del>
              </div>
              <div class="each-pri-right"></div>
            </div>
          </div>
        </div>
      </div>
      <div class="back-top" @click="backtop" ref="backtop"></div>
    </div>
  </div>
</template>

<script>
import timecountdown from "../widgets/timecountdown.vue";
import CartAddPro from "../widgets/CartAddPro.vue";
import store from "../../store/index.js"
// import BackTop from "../widget/BackTop.vue";
import axios from "axios";
export default {
  name: "cart",
  store,
  computed:{
    isAdd(){
      return this.$store.state.isAdd
    },
    hasnotlogin(){
      return this.$store.state.hasnotlogin
    }
  },
  data() {
    return {
      proList: [],
      cartPro: [],
      isblackclick:false,
    };
  },
  components: {
    // "back-top": BackTop,
    "time-count": timecountdown,
    "cartadd-list":CartAddPro
  },
 
  methods: {
    cartback() {
      this.$router.go(-1);
    },
    login() {
      this.$router.push("/login");
    },
    backtop() {
      document.documentElement.scrollTop = document.body.scrollTop = 0;
    },
    cartScroll() {
      let rect = this.$refs.want.getBoundingClientRect();
      if (rect.top <= 0) {
        this.$refs.backtop.style.display = "block";
      } else {
        this.$refs.backtop.style.display = "none";
      }
    },
    blackbtnclick(){
      this.isblackclick=!this.isblackclick
    },
    gotootherpage(a){
      if (a == 0) {
        this.$router.push({ path: "/" }).catch(function() {
          return;
        });
      }

      if (a == 1) {
        this.$router.push({ path: "/category" }).catch(function() {
          return;
        });
      }
      if (a == 2) {
        this.$router.push({ path: "/cart" }).catch(function() {
          return;
        });
      }
      if (a == 3) {
        this.$router.push({ path: "/login" }).catch(function() {
          return;
        });
      }
    }
  },
  created() {
    let that = this;
    axios.get("data/floatitem.json").then(function(response) {
      that.proList = response.data.result;
    });
    axios.get("data/cartPro.json").then(function(response) {
      that.cartPro = response.data.result;
    });

    window.addEventListener("scroll", this.cartScroll);
  },
  destroyed() {
    window.removeEventListener("scroll", this.cartScroll);
  }
};
</script>

<style scoped>

.cart-container {
  width: 100%;
  padding-bottom: 50px;
}

.cart-body {
  padding-top: 44px;
  width: 100%;
  height: 100%;
  overflow: auto;
  background: rgb(247, 247, 247);
}

.cart-header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 44px;
  background: #ffffff;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  z-index: 1000;
}

.cartback {
  display: block;
  width: 44px;
  height: 44px;
  background: url("../../../public/images/back.png") no-repeat 50%;
  background-size: 20px;
}

.cart-header-title {
  height: 44px;
  line-height: 44px;
  font-size: 18px;
  color: #333;
  text-align: center;
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.more {
  display: block;
  width: 44px;
  height: 44px;
  background: url("../../../public/images/threepoint.png") no-repeat 50%;
  background-size: 20px;
}

.cart-login {
  padding: 30px 0 15px;
  text-align: center;
}

.cart-login img {
  width: 90px;
  height: 90px;
  border: 0 none;
  vertical-align: top;
}

.cart-login p {
  font-size: 16px;
  color: rgba(51, 51, 51, 0.66);
  line-height: 24px;
  margin: 11px 0;
  vertical-align: baseline;
}

.cart-login div {
  width: 60px;
  height: 30px;
  border: 1px solid #e93b3d;
  color: #e93b3d;
  font-size: 14px;
  line-height: 30px;
  border-radius: 4px;
  margin: 0 auto 15px;
}

.jd-seckill {
  position: relative;
  margin: 15px 0;
  height: 12px;
  line-height: 12px;
  text-align: center;
  font-size: 12px;
  color: #999;
}

.jd-seckill-text {
  z-index: 2;
  position: relative;
  padding: 0 15px;
  background-color: #f7f7f7;
}

.jd-seckill-text::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  margin-top: -2px;
  width: 4px;
  height: 4px;
  background-color: #ccc;
  transform: rotate(45deg);
}

.jd-seckill-text::after {
  content: "";
  position: absolute;
  right: 0;
  top: 50%;
  margin-top: -2px;
  width: 4px;
  height: 4px;
  background-color: #ccc;
  transform: rotate(45deg);
}

.jd-seckill::after {
  content: "";
  position: absolute;
  z-index: 1;
  pointer-events: none;
  background-color: #ccc;
  height: 1px;
  left: 10px;
  right: 10px;
  top: 50%;
}

.jd-seckill-list {
  width: 100%;
}

.seckill {
  margin: 0 0 10px 10px;
  background-color: #fff;
  border-radius: 4px 0 0 4px;
}

.seckill-top {
  display: flex;
  height: 45px;
  line-height: 45px;
}

.seckill-top-left {
  font-size: 16px;
  color: #333;
  margin: 0 10px 0 15px;
  font-weight: 700;
}

.seckill-bottom {
  /* position: relative; */
  padding: 0 15px 15px;
  font-size: 0;
  font-family: none;
  white-space: nowrap;
  /* overflow: hidden; */
  overflow-x: auto;
  height: 141px;
}

.seckill-bottom::-webkit-scrollbar {
  display: none;
}

.seckill-bottom-item {
  display: inline-block;
  vertical-align: top;
  /* position: relative; */
  text-align: center;
  width: 24%;
  margin-right: 10px;
  padding: 0 5px 5px;
  border-radius: 4px;
}

.seckill-bottom-img {
  width: 100%;
  height: auto;
  border-radius: 4px;
  border: 0 none;
  vertical-align: top;
}

.seckill-bottom-p {
  font-size: 16px;
  margin-top: 5px;
  color: #e93b3d;
  font-family: arial;
}

.seckill-bottom-del {
  display: block;
  font-size: 12px;
  color: #ccc;
  line-height: 1;
}

.get-more {
  display: inline-block;
  width: 45px;
  position: relative;
  /* position: absolute; */
  height: 100%;
  /* right: 10px;
    bottom: 20px; */
  background-color: #f7f7f7;
}

.get-more span {
  display: block;
  font-size: 12px;
  color: #999;
  position: absolute;
  left: 12px;
  top: 50%;
  margin-top: -25px;
  padding-bottom: 12px;
  writing-mode: vertical-rl;
  text-align: left;
  letter-spacing: 2px;
}

.something-want-to {
  position: relative;
  margin: 15px 0;
  height: 12px;
  line-height: 12px;
  text-align: center;
  font-size: 12px;
  color: #999;
}

.something-want-to-text {
  z-index: 2;
  position: relative;
  padding: 0 15px;
  background-color: #f7f7f7;
}

.something-want-to-text::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  margin-top: -2px;
  width: 4px;
  height: 4px;
  background-color: #ccc;
  transform: rotate(45deg);
}

.something-want-to-text::after {
  content: "";
  position: absolute;
  right: 0;
  top: 50%;
  margin-top: -2px;
  width: 4px;
  height: 4px;
  background-color: #ccc;
  transform: rotate(45deg);
}

.something-want-to::after {
  content: "";
  position: absolute;
  z-index: 1;
  pointer-events: none;
  background-color: #ccc;
  height: 1px;
  left: 10px;
  right: 10px;
  top: 50%;
}

.something-want-to-list {
  width: 100%;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}

.each {
  background: #fff;
  position: relative;
  width: 50%;
  margin-bottom: 1px;
  padding: 15px 15px 0;
  box-sizing: border-box;
}

.each-top {
  /* position: absolute;
  top: 0;
  left: 0; */
  width: 157px;
  height: 157px;
}

.each-top img {
  width: 100%;
  height: 100%;
}

.each-bottom {
  width: 100%;
}

.each-des {
  margin: 12px 0 4px;
  font-size: 12px;
  color: #333;
  line-height: 18px;
  height: 36px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.each-des img {
  display: inline-block;
  vertical-align: middle;
  margin-top: 2px;
  margin-right: 5px;
  height: 14px;
  border: 0 none;
  vertical-align: top;
}

.each-pri {
  width: 100%;
  overflow: hidden;
}

.each-pri-left {
  display: inline-block;
}

.each-pri-left-one {
  display: inline-block;
  font-size: 12px;
  color: #e93b3d;
  margin-right: 3px;
  line-height: 20px;
}

.each-pri-left-two {
  /* margin-top: -4px; */
  color: #e4393c;
  background: #fff;
  display: inline-block;
  position: relative;
  border: 1px solid #e4393c;
  border-radius: 2px;
  min-width: 16px;
  font-size: 10px;
  line-height: 15px;
  vertical-align: middle;
  margin-right: 5px;
  text-align: center;
}

.each-pri-left-three {
  font-size: 12px;
  color: #999;
  text-decoration: line-through;
  line-height: 18px;
}

.back-top {
  width: 40px;
  height: 40px;
  font-size: 0;
  overflow: hidden;
  background-color: rgba(0, 0, 0, 0.7);
  border-radius: 3px 0 0 3px;
  z-index: 101;
  background-repeat: no-repeat;
  background-position: 50%;
  background-image: url("../../../public/images/backtop.png");
  background-size: 25px;
  position: fixed;
  bottom: 200px;
  right: 0;
  display: none;
}
</style>